package com.ease.framework.gef4g {
   import com.ease.framework.gef.IEditPart;
   import com.ease.framework.gef.events.GraphicalZoomEvent;
   import com.ease.framework.workbench.viewer.Viewer;

   import mx.core.Container;
   import mx.effects.Zoom;

   /**
    * 这是Diagram Viewer实现类.
    *
    * Viewer中会有一个RootEditPart，用于管理Layer. RootEditPart会有对应的RootFigure，在RootFigure中会有不同Layer来处理.
    */
   public class GraphicalViewer extends Viewer implements IGraphicalViewer {

      protected var _viewport:IViewport;

      protected var _editpart:IEditPart;

      protected var zoom:Zoom = new Zoom();
      protected var currentZoomNum:Number = 1.0;

      public function GraphicalViewer() {
         super();
      }

      override public function configControl():void {
         super.configControl();
         IGraphicalViewerControl(this.getControl()).setViewer(this);
         zoom.target = getViewport();
         zoom.zoomWidthTo = 1;
         zoom.zoomHeightTo = 1;
      }

      public function getZoom():Zoom {
         return zoom;
      }

      public function doZoom(zoomNum:Number):void {
         currentZoomNum = zoomNum;
         if (zoom.target == null) {
            zoom.target = getViewport();
         }

         zoom.originX = 0;
         zoom.originY = 0;
         zoom.zoomHeightTo = currentZoomNum;
         zoom.zoomWidthTo = currentZoomNum;
         zoom.play();
         Container(getControl()).invalidateDisplayList();

         Container(getControl()).dispatchEvent(new GraphicalZoomEvent(GraphicalZoomEvent.ZOOM_CHANGED, true));
      }

      public function getZoomCurrentNumber():Number {
         return currentZoomNum;
      }

      public function getViewport():IViewport {
         //return _viewerControl.getViewport();
         return _viewport;
      }

      public function setViewport(viewport:IViewport):void {
         _viewport = viewport;
         Container(getControl()).addChild(_viewport as Container);
         _viewport.width = Container(getControl()).width;
         _viewport.height = Container(getControl()).height;
      }

      public function getEditPart():IEditPart {
         return _editpart;
      }

      public function setEditPart(editPart:IEditPart):void {
         _editpart = editPart;
      }
   }
}
